package util

import android.content.Context
import android.graphics.Color
import android.widget.TextView
import com.bigkoo.pickerview.TimePickerView
import java.text.SimpleDateFormat
import java.util.*

class TimeSelectedUtil(context: Context) {
    var selectedDate: Calendar = Calendar.getInstance();
    var startDate: Calendar = Calendar.getInstance();
    var endDate: Calendar = Calendar.getInstance();
    private var booleanArray: BooleanArray = booleanArrayOf(true, true, true,false,false,false)
    lateinit var timePickerView: TimePickerView
    private val context:Context=context
    fun timeSelected() :TimePickerView{
        startDate.set(1900, 0, 1);
        endDate.set(2040, 11, 31);
        //时间选择器
        timePickerView=TimePickerView.Builder(context, TimePickerView.OnTimeSelectListener { date, v ->
            val tv= v as TextView
            tv.text = (getTimes(date))
        })

            //年月日时分秒的显示与否，不设置则默认全部显示，这里可自行定制
            .setCancelText("取消")
            .setSubmitText("确认")
            .setType(booleanArray)
            .setLabel(" ", "", "","","","")
            .isCenterLabel(true)
            .setDividerColor(Color.DKGRAY)
            .setContentSize(20)
            .setDate(selectedDate)
            .setRangDate(startDate, endDate)
            .setDecorView(null)
            .build()
        return timePickerView
    }
    private fun getTimes(date: Date):String {
        val format= SimpleDateFormat("yyyy-MM-dd ")
        return format.format(date)
    }
    }
